var tr_select;
 function redondear(amount) {
 var val = parseFloat(amount);
 if (isNaN(val)) {
 return "0.00";
 }
 if (val <= 0) {
 return "0.00";
 }
 val += "";
 // Next two lines remove anything beyond 2 decimal places
 if (val.indexOf('.') == -1) {
 return val + ".00";
 }
 else {
 val = val.substring(0, val.indexOf('.') + 3);
 }
 val = (val == Math.floor(val)) ? val + '.00' : ((val * 10 ==
 Math.floor(val * 10)) ? val + '0' : val);
 return val;
 }



jQuery(document).ready(function($) {
    $.getJSON("sale_header_read.php", {
        id: $('#header_id').val()
    }).done(function(data) {
        $('#serie').val(data[0].serie);
        $('#numero').val(data[0].number);
        $('#emission_date').val(data[0].emission_date.replace(/-/g, "/"));
        $('#cancellation_date').val(data[0].cancellation_date.replace(/-/g, "/"));

        $('#client_name').val(data[0].name);
        $('#client_ruc').val(data[0].ruc);
        $('#client_address').val(data[0].address);

        $('#subtotal_g').val(data[0].subtotal.replace("$", ""));
        $('#igv_g').val(data[0].igv.replace("$", ""));
        $('#total_g').val(data[0].total.replace("$", ""));
    });

    $.getJSON("sale_header_detail_read.php", {
        id: $('#header_id').val()
    }).done(function(data) {
        $("#detail > tbody").html("");
        $.each(data, function(key, val) {
            $("#detail tbody").append("<tr class=\"item-row\">" +
                    "<td>" +
                    
                    "<input type=\"text\" id=\"name\" value=\"" + val.fullname+ "\" readonly=\"readonly\" class=\"form-control input-sm\">" +
                    "</td>" +
                    "<td>" +
                    "<input type=\"text\" id=\"quantity\" value=\"" + val.quantity+ "\" readonly=\"readonly\" class=\"form-control input-sm\"  style=\"text-align:right\" >" +
                    "</td>" +
                    "<td>" +
                    "<div class=\"input-group\">" +
                    "<span class=\"input-group-addon\">S/.</span>" +
                    "<input type=\"text\" id=\"price\" value=\"" + val.price.replace("$", "") + "\" class=\"form-control input-sm\" readonly=\"readonly\"  style=\"text-align:right\" >" +
                    "</div>" +
                    "</td>" +
                    "<td>" +
                    "<div class=\"input-group\">" +
                    "<span class=\"input-group-addon\">S/.</span>" +
                    "<input type=\"text\" readonly=\"readonly\" id=\"total\" value=\"" + val.total.replace("$", "") + "\" class=\"form-control input-sm\"  style=\"text-align:right\" >" +
                    "</div>" +
                    "</td>" +
                    "<td>" +
                    "<div class=\"input-group\">" +
                    "</div>" +
                    "</td>" +
                    "</tr>");

        });
    });


});
